import { v4 as uuidv4 } from 'uuid'
export default (getDetail) => {
  // 工作任务处理SGTaskListTemporary
  if (getDetail.SGWorkEndReport.length === 0) {
    getDetail.SGWorkEndReport = [
      {
        workEndReportID: uuidv4(),
        workTicketID: getDetail.mRID,
        workingControllerId: '',
        workingControllerName: '',
        workingLicensorId: '',
        workingLicensorName: '',
        workEndTime: ''
      }
    ]
  }
  // 班成员
  // getDetail.SGTeamMembers1 = getDetail.SGTeamMembers.filter(item => item.staffType === 'Team')
  // getDetail.SGTeamMembers2 = getDetail.SGTeamMembers.filter(item => item.staffType === 'OutSourcing')
  // getDetail.SGTeamMembers3 = getDetail.SGTeamMembers.filter(item => item.staffType === 'Factory')
  getDetail.SGTeamMembers3 = getDetail.SGTeamMembers.filter(item => item.staffType === 'Factory')
  getDetail.SGTeamMembers2 = []
  getDetail.SGTeamMembers1 = getDetail.SGTeamMembers.filter(item => ['OutSourcing', 'Team'].includes(item.staffType))
  // 安全措施
  getDetail.SGSafetyMeasures1 = getDetail.SGSafetyMeasures.filter(item => item.conOfSecurityMeasuresTypeCode === 'ConditionsMattersNeeding')
  getDetail.SGSafetyMeasures2 = getDetail.SGSafetyMeasures.filter(item => item.conOfSecurityMeasuresTypeCode === 'AdditionaMattersNeedingAttention')
  getDetail.SGSafetyMeasures3 = getDetail.SGSafetyMeasures.filter(item => item.conOfSecurityMeasuresTypeCode === 'EquStatusNeeding')
  if (getDetail.SGTeamMembersSignIn.length === 0 && getDetail.SGPersonnelChangeDetailRecords.length === 0 && getDetail.processStatus === 'Execute') {
    getDetail.SGTeamMembersSignIn = getDetail.SGTeamMembers.map(memberItem => {
      return {
        listID: uuidv4(),
        workTicketID: getDetail.mRID,
        staffType: memberItem.staffType || '',
        staffId: memberItem.staffId || '',
        staffName: memberItem.staffName || '',
        departmentId: memberItem.deptId || '',
        departmentName: memberItem.dept || '',
        unitId: memberItem.unitId || '',
        unitName: memberItem.unit || '',
        signType: 'ElectronicSign',
        fileId: ''
      }
    })
  }
  getDetail.SGTeamMembersSignIn3 = getDetail.SGTeamMembersSignIn.filter(item => item.staffType === 'Factory') // 外包
  getDetail.SGTeamMembersSignIn1 = getDetail.SGTeamMembersSignIn.filter(item => ['OutSourcing', 'Team'].includes(item.staffType))
  getDetail.SGTeamMembersSignIn2 = []
  // 安全交底以及安全措施
  const safeStep = getDetail.WorkTicketEnclosure
  if (safeStep && safeStep.length > 0) {
    getDetail.workTicketEnclosure1 = safeStep.filter(safe => safe.EnclosureClassify === 'bqhzp')
    getDetail.workTicketEnclosure2 = safeStep.filter(safe => safe.EnclosureClassify === 'SafetyMeasures')
    getDetail.workTicketEnclosure3 = safeStep.filter(safe => safe.EnclosureClassify === 'MeasuresPlan')
    getDetail.workTicketEnclosure4 = safeStep.filter(safe => safe.EnclosureClassify === 'SiteSurveySheet')
    getDetail.workTicketEnclosure5 = safeStep.filter(safe => safe.EnclosureClassify === 'SitePhotos')
    getDetail.workTicketEnclosure6 = safeStep.filter(safe => safe.EnclosureClassify === 'End')
    getDetail.workTicketEnclosure7 = safeStep.filter(safe => safe.EnclosureClassify === 'SurveySheetFirst')
  }
  getDetail.SGPersonnelChangeDetailRecords = (getDetail.SGPersonnelChangeDetailRecords && getDetail.SGPersonnelChangeDetailRecords.map(personnelChange => {
    personnelChange.isDisabled = true
    // personnelChange.isAdd = false
    return personnelChange
  })) || []
  return getDetail
}
